package classify

import (
	"errors"
	classifyDto "news_for_deepseek_interface/dto/admin/classify"
	"news_for_deepseek_interface/model"
)

func Delete(params classifyDto.DeleteRequest) error {

	for _, v := range params.Id {
		var classify model.ClassifyModel
		db := model.GetInstance().GetDB()
		if err := db.Where("id = ?", v).First(&classify).Error; err != nil {
			return errors.New("分类不存在")
		}

		db.Where("id = ?", v).Delete(&model.ClassifyModel{})

		db.Where("find_in_set(?, parent_path)", v).Delete(&model.ClassifyModel{})
	}

	return nil
}
